package com.ruoyi.web.controller.store.pan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.PanOverflowReportDetail;
import com.ruoyi.common.core.domain.entity.StoreOutDetail;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.mapper.RestaurantStoreResourceMapper;
import com.ruoyi.system.service.IPanOverflowReportDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 报损单/报溢单明细Controller
 *
 * @author wlmes
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/overflow/detail")
@Api(tags = "报损单/报溢单明细相关接口")
public class PanOverflowReportDetailController extends BaseController {
    @Autowired
    private IPanOverflowReportDetailService panOverflowReportDetailService;
    @Resource
    RestaurantStoreResourceMapper storeResourceMapper;

    /**
     * 查询报损单/报溢单明细列表
     */
    @GetMapping("/list")
    @ApiOperation("查询报损单/报溢单明细列表")
    public TableDataInfo list(PanOverflowReportDetail panOverflowReportDetail) {
        startPage();
        List<PanOverflowReportDetail> list = panOverflowReportDetailService.selectPanOverflowReportDetailList(panOverflowReportDetail);
        for (PanOverflowReportDetail overflowReportDetail : list) {
            String name = storeResourceMapper.getName(overflowReportDetail.getResourceId());
            overflowReportDetail.setName(name);
            overflowReportDetail.setResourceName(name);
        }
        return getDataTable(list);
    }

    /**
     * 导出报损单/报溢单明细列表
     */
//    @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "报损单/报溢单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出报损单/报溢单明细列表")
    public AjaxResult export(PanOverflowReportDetail panOverflowReportDetail) {
        List<PanOverflowReportDetail> list = panOverflowReportDetailService.selectPanOverflowReportDetailList(panOverflowReportDetail);
        ExcelUtil<PanOverflowReportDetail> util = new ExcelUtil<PanOverflowReportDetail>(PanOverflowReportDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取报损单/报溢单明细详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取报损单/报溢单明细详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(panOverflowReportDetailService.selectPanOverflowReportDetailById(id));
    }

    /**
     * 新增报损单/报溢单明细
     */
//    @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "报损单/报溢单明细", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增报损单/报溢单明细")
    @RepeatSubmit
    public AjaxResult add(@RequestBody PanOverflowReportDetail panOverflowReportDetail) {
            return toAjax(panOverflowReportDetailService.insertPanOverflowReportDetail(panOverflowReportDetail));
    }

    /**
     * 修改报损单/报溢单明细
     */
//    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "报损单/报溢单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改报损单/报溢单明细")
    @RepeatSubmit
    public AjaxResult edit(@RequestBody PanOverflowReportDetail panOverflowReportDetail) {
            return toAjax(panOverflowReportDetailService.updatePanOverflowReportDetail(panOverflowReportDetail));
    }

    /**
     * 删除报损单/报溢单明细
     */
//    @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "报损单/报溢单明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除报损单/报溢单明细")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] ids) {
            return toAjax(panOverflowReportDetailService.deletePanOverflowReportDetailByIds(ids));
    }
}
